<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="添加h1" onclick="f1()">
<input type="button" value="添加图片" onclick="f2()">
<script>
  function f1() {
    let i=document.querySelector("input");
    let h1=document.createElement("h1");
    h1.innerText=i.value;
    //添加到页面中
    document.body.append(h1);
  }
  function f2() {
    //创建图片标签
    let img=document.createElement("img");
    //设置图片路径
    img.src="../b.png";
    //添加图片到页面中
    document.body.append(img);
  }
</script>
</body>
</html>